# coding=utf-8
from re import template
from string import Template
from typing import List
from utils.templete_file import TempleteFile

cpp_header_templete=Template(
"""
#pragma once

${inlcude}

namespace ${namespace}{

    ${members}
}
"""
)



class CPPHeader(TempleteFile):

    def __init__(self,namespace:str) -> None:
        self.namespace=namespace
        self.includes=[]
        self.members=[]

    def addInclude(self,name,local=False):
        self.includes.append("#include {0}".format("<{0}>".format(name) if local is False else "\"{0}\"".format(name)))
    
    def addMember(self,member:TempleteFile):
        self.members.append(member)
    
    def __str__(self) -> str:
        return cpp_header_templete.substitute(
            inlcude="\n".join(self.includes),
            namespace=self.namespace,
            members = "".join([member.__str__() for member in self.members])
        )


c_header_templete=Template(
"""
#ifndef ${file_name}_H
#define ${file_name}_H

${declaries}

${members}

#endif
"""
)


class CHeader(TempleteFile):

    def __init__(self,file_name:str) -> None:
        self.file_name = file_name
        self.declaries=[]
        self.members=[]

    def include(self,name,local=False):
        self.declaries.append("#include {0}".format("<{0}>".format(name) if local is False else "\"{0}\"".format(name)))

    def define(self,info):
        self.declaries.append("#define {0}".format(info))
    
    def addMember(self,member:TempleteFile):
        self.members.append(member)

    def __str__(self) -> str:
        return c_header_templete.substitute(
            file_name=self.file_name.upper(),
            declaries="\n".join(self.declaries),
            members = "\n".join([member.__str__() for member in self.members])
        )


class Method(TempleteFile):

    templete=Template("""
${return_type} ${name}(${params})
    """)
    def __init__(self,method_name:str,return_type:str,*param) -> None:
        self.name = method_name
        self.return_type= return_type
        self.params=param
    
    